package com.onlyxiahui.common.util;

/**
 * Date 2019-01-11 14:14:40<br>
 * Description
 *
 * @author XiaHui<br>
 * @since 1.0.0
 */
public class OnlyPropertyUtil {

	public static boolean isEmpty(Object o) {
		return (null == o || "".equals(o));
	}

	public static boolean isNotEmpty(Object o) {
		return (null != o && !"".equals(o));
	}

	public static boolean isPrimitive(Class<?> o) {
		return (o.isPrimitive()) || (o == Integer.class) || (o == Long.class) || (o == Float.class)
				|| (o == Double.class) || (o == Byte.class) || (o == Character.class) || (o == Boolean.class)
				|| (o == Short.class);
	}

	public static boolean isInteger(Class<?> o) {
		return (o == Integer.class);
	}

	public static boolean isLong(Class<?> o) {
		return (o == Long.class);
	}

	public static boolean isFloat(Class<?> o) {
		return (o == Float.class);
	}

	public static boolean isDouble(Class<?> o) {
		return (o == Double.class);
	}

	public static boolean isByte(Class<?> o) {
		return (o == Byte.class);
	}

	public static boolean isCharacter(Class<?> o) {
		return (o == Character.class);
	}

	public static boolean isBoolean(Class<?> o) {
		return (o == Boolean.class);
	}

	public static boolean isShort(Class<?> o) {
		return (o == Short.class);
	}

	/**
	 * 判断对象是否为8种基本类型的对象。
	 *
	 * @param o
	 * @return boolean
	 */
	public static boolean isPrimitive(Object o) {
		return (o instanceof Integer) || (o instanceof Long) || (o instanceof Float) || (o instanceof Double)
				|| (o instanceof Byte) || (o instanceof Character) || (o instanceof Boolean) || (o instanceof Short)
				|| o.getClass().isPrimitive();
	}

	/**
	 * Description 是否为字符串类型 <br>
	 * Date 2019-03-30 17:31:10<br>
	 *
	 * @param o
	 * @return boolean
	 * @since 1.0.0
	 */
	public static boolean isString(Object o) {
		return (o instanceof String);
	}

	/**
	 * Description 是否为字符串类型 <br>
	 * Date 2019-03-30 17:31:01<br>
	 *
	 * @param o
	 * @return boolean
	 * @since 1.0.0
	 */
	public static boolean isString(Class<?> o) {
		return (o == String.class);
	}

	@SuppressWarnings("unchecked")
	public static <T> T getDefaultValue(Class<T> clazz) {
		Object object = null;

		if (clazz == int.class) {
			object = 0;
		}
		if (clazz == long.class) {
			object = 0L;
		}
		if (clazz == float.class) {
			object = 0.0F;
		}
		if (clazz == double.class) {
			object = 0.00D;
		}
		if (clazz == byte.class) {
			object = (byte) 0;
		}
		if (clazz == char.class) {
			object = '\u0000';
		}
		if (clazz == short.class) {
			object = 0;
		}
		if (clazz == boolean.class) {
			object = false;
		}
		return ((T) object);

	}

	/**
	 * Date 2019-03-30 17:17:16<br>
	 * Description int to long
	 *
	 * @param i
	 * @return long
	 * @since 1.0.0
	 */
	public static long intToLong(int i) {
		long l = i & 0x7fffffffL;
		if (i < 0) {
			l |= 0x080000000L;
		}
		return l;
	}
}
